package com.matt.repository.materials;

import com.matt.domain.materials.Materiels;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import com.matt.domain.materials.UserMateriels;

import java.util.List;

public interface UserMaterielsRepository extends JpaRepository<UserMateriels, String>, JpaSpecificationExecutor<UserMateriels> {

    UserMateriels findFirstByAidAndUidAndMateriels(String areaId, String userId, Materiels materiel);

    @EntityGraph("UserMateriels.withMateriels")
    List<UserMateriels> findAllByAidAndCountGreaterThanAndTypeOrderByCreatedDesc(String areaId, int count, int type);

    @EntityGraph("UserMateriels.withMateriels")
    List<UserMateriels> findAllByAidAndUidAndCountGreaterThanAndTypeOrderByCreatedDesc(String areaId, String uid, int count, int type);
}